package com.example.demoeventspring.controller;

import com.example.demoeventspring.event.LoginNotifyEvent;
import com.example.demoeventspring.event.RegisterNotifyEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class Index {
    @Autowired
    ApplicationContext applicationContext;

    @GetMapping("/demo")
    public String index() {
        // 业务实体 事件: 注册通知
        RegisterNotifyEvent registerNotifyEvent = new RegisterNotifyEvent("fox", "1000", "user", new Date());
        // 发布事件
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);

        // 业务实体 事件:登录通知
        LoginNotifyEvent loginNotifyEvent = new LoginNotifyEvent("admin", "1", "admin", new Date());
        // 发布事件
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        //
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        this.applicationContext.publishEvent(registerNotifyEvent);
        this.applicationContext.publishEvent(loginNotifyEvent);
        return "ok";
    }
}
